local skel = fk.CreateSkill {
  name = "emo__huangli",
}

Fk:loadTranslationTable{
  ["emo__huangli"] = "谎立门面",
  [":emo__huangli"] = "每回合限一次，你可以视为使用【瞒天过海】或【推心置腹】，然后卜算手中因此获得的牌。",

  ["#emo__huangli"] = "谎立门面:使用【瞒天过海】或【推心置腹】",
}

skel:addEffect("viewas", {
  anim_type = "control",
  prompt = "#emo__huangli",
  pattern = "underhanding,sincere_treat",
  interaction = function(self, player)
    return UI.ComboBox { choices = { "underhanding", "sincere_treat" } }
  end,
  card_num = 0,
  view_as = function (self, player, cards)
    if self.interaction.data == nil then return nil end
    local c = Fk:cloneCard(self.interaction.data)
    c.skillName = skel.name
    return c
  end,
  after_use = function (self, player, use)
    local room = player.room
    if player.dead then return end
    if use.extra_data and use.extra_data[skel.name] then
      local ids = table.filter(use.extra_data[skel.name], function (id)
        return table.contains(player.player_cards[Player.Hand], id)
      end)
      if #ids == 0 then return end
      local moves = {}
      local result = room:askToGuanxing(player, { cards = ids, skill_name = skel.name, skip = true })
      if #result.top > 0 then
        table.insert(moves, {
          from = player,
          ids = table.reverse(result.top),
          toArea = Card.DrawPile,
          moveReason = fk.ReasonPut,
          skillName = skel.name,
          proposer = player,
          moveVisible = false,
          visiblePlayers = {player},
        })
      end
      if #result.bottom > 0 then
        table.insert(moves, {
          from = player,
          ids = result.bottom,
          toArea = Card.DrawPile,
          moveReason = fk.ReasonPut,
          skillName = skel.name,
          proposer = player,
          moveVisible = false,
          visiblePlayers = {player},
          drawPilePosition = -1,
        })
      end
      room:moveCards(table.unpack(moves))
    end
  end,
  times = function (self, player)
    return 1 - player:usedSkillTimes(skel.name)
  end,
  enabled_at_play = function(self, player)
    return player:usedSkillTimes(skel.name) == 0
  end,
  enabled_at_response = function (self, player, response)
    if not response then
      return player:usedSkillTimes(skel.name) == 0
    end
  end,
})

skel:addEffect(fk.AfterCardsMove, {
  can_refresh = function (self, event, target, player, data)
    return player.seat == 1
  end,
  on_refresh = function (self, event, target, player, data)
    local current = player.room.logic:getCurrentEvent()
    local use_event = current:findParent(GameEvent.UseCard)
    if use_event == nil then return end
    local use = use_event.data
    if table.contains(use.card.skillNames, skel.name) then
      for _, move in ipairs(data) do
        if move.to == use.from and move.toArea == Card.PlayerHand then
          for _, info in ipairs(move.moveInfo) do
            use.extra_data = use.extra_data or {}
            use.extra_data[skel.name] = use.extra_data[skel.name] or {}
            table.insertIfNeed(use.extra_data[skel.name], info.cardId)
          end
        end
      end
    end
  end,
})

return skel
